package com.whmnx.main.ui.model;

import android.app.Application;
import android.text.Html;
import android.text.Spanned;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.whmnx.base.bean.MsgBean;
import com.whmnx.base.constants.Constants;
import com.whmnx.base.http.CallBack;
import com.whmnx.base.http.HttpClient;
import com.whmnx.main.databinding.ActivityMsgDetailBinding;
import com.whmnx.main.ui.activity.MsgDetailActivity;

import java.util.HashMap;
import java.util.Map;

import me.goldze.mvvmhabit.utils.SPUtils;

/**
 * author : huang
 * date   : 2020/11/6 0006 10:20
 * version: 1.0
 */
public class MsgDelModel extends ToolbarViewMainModel{
    MsgDetailActivity mActivity;
    ActivityMsgDetailBinding mBinding;

    public ObservableField<String> Message_Content = new ObservableField<>("");
    public ObservableField<String> CreateDate = new ObservableField<>("");

    public MsgDelModel(@NonNull Application application) {
        super(application);
    }

    public void initToolbar(MsgDetailActivity msgDetailActivity, ActivityMsgDetailBinding binding) {
        this.mActivity = msgDetailActivity;
        this.mBinding = binding;
        setTitleText("消息详情");
        initView();
    }

    private void initView() {
        Map<String, Object> params = new HashMap<>();
        params.put("Id",mActivity.getIntent().getStringExtra("id"));
        params.put("uId", SPUtils.getInstance().getString(Constants.USERID));
        HttpClient.get(mActivity, Constants.MESSAGEDETAIL, params,new CallBack<MsgBean>() {
            @Override
            public void onSuccess(MsgBean msgBean) {
                Spanned sp = Html.fromHtml(msgBean.getMessage_Content());
                mBinding.tv1.setText(sp);
                CreateDate.set(msgBean.getCreateDate());
            }
        });
    }
}
